<?php
namespace app\wxapp\admin;

use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use app\wxapp\model\Log as LogModel;
use app\wxapp\model\Users as UsersModel;

class Log extends Admin
{
    public function index()
    {
        // 查询
        $map = $this->getMap();
        // 排序
        $order = $this->getOrder('update_time desc');
        // 数据列表
        $data_list = LogModel::where($map)->order($order)->paginate();

        $list_type = UsersModel::where('status', 1)->column('id,nickname');

        // 使用ZBuilder快速创建数据表格
        return ZBuilder::make('table')
            ->setSearch(['uid' => '用户UID'])// 设置搜索框
            ->addColumns([ // 批量添加数据列
                ['id', 'ID'],
                ['uid', 'UID', 'select', $list_type],
                ['content', '内容', 'text'],
                ['create_time', '创建时间', 'datetime'],
                ['update_time', '更新时间', 'datetime'],
            ])
            ->addOrder('id,create_time,update_time')
            ->setRowList($data_list)// 设置表格数据
            ->fetch(); // 渲染模板
    }
}